<?php


namespace app\api\model;


use think\Model;

/*
 * 标签分类
 * */
class Label extends Model
{


    // 表名
    protected $name = 'label';


    public function getLabel($params)
    {
        $new    = [];
        $res    = self::where('pid',0)->field('id,name')->select();
        $child  = self::where('pid','>',0)->field('id,pid,name')->select();
        $child  = json_decode(json_encode($child),true);
        $chi    = [];
        foreach ($child as $vo)$chi[$vo['pid']][] = $vo;
        foreach ($res as $v) {
            $v->child   = $chi[$v->id] ?? [];
        }
        return api_message($res);
    }

}